package com.mapeditor.graph 
{
	import com.mapeditor.math.Vector3;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.net.URLRequest;
	/**
	 * ...
	 * @author Osvaldo Cassaniga Junior
	 */
	public class ShapeImage extends Sprite
	{
		private var _loader:Loader;
        private var _mShape:Matrix;
        public var w:Number;
		public var h:Number;
		public var alphaValue:Number;
		
		public function ShapeImage(requestImg:String,w:Number=0,h:Number=0,alpha:Number=1) 
		{
			this.w = w;
			this.h = h;
			this.alphaValue = alpha;
			
			_loader = new Loader();            
            _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _loaded, false, 0, true);
            _loader.load(new URLRequest(requestImg));
		}//end of method
		private function _loaded(event:Event):void {
            addChild(_loader.content);          
            this.alpha = alphaValue;
			if (this.w > 0 && this.h > 0)
			{
				this.width = this.w;
				this.height = this.h;
			}
            
			_mShape = this.transform.matrix;
            
			/*if (degrees != 0)
			{
				this.transform.matrix = _mShape;
				_rotate(this.degrees);
			}*/
			this.x = -this.width / 2;
			this.y = -this.height / 2;
        }//end of method
		
		private function _rotate(angleDegrees:Number):void {
            
            var point:Vector3=new Vector3(this.w/2, this.h/2);
            var m:Matrix=this.transform.matrix;
            m.tx -= point.x;
            m.ty -= point.y;
            m.rotate(angleDegrees*(Math.PI/180));
            m.tx += point.x;
            m.ty += point.y;
            this.transform.matrix=m;
        }//end of method
		
	}

}